﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows.Controls;
using System.Windows.Data;
using FinPlusCommon;
using System.Xml;
using u = FinPlusUtility.Utility;
using log = Logger.Logger;

namespace FinPlusWPFControls
{
    public partial class FinPlusMapDiagram : FinPlusControl
    {
        public override IFunctions Adaptor { get { return _funcs; } }
        public override string TestString { get { return Adaptor.ToString(); } }

        public XmlDocument xmlDocument { get { return _xmldocument; } set { _xmldocument = value; BindXMLDocument(); } }

        private enum DockControls { Functions }
        private IFunctions _funcs;
        private XmlDocument _xmldocument;

        //construct
        public FinPlusMapDiagram()
        {
            InitializeComponent();
            IsValid = true;
        }

        //common control interface
        public override void Dock(object control, string dock)
        {
            try
            {
                switch (u.EnumParse<DockControls>(control.GetType().Name, DockControls.Functions))
                {
                    case DockControls.Functions: AddFunction((IFunctions)control); break;
                }
            }
            catch (Exception e)
            {
                IsValid = log.Log(Logger.Level.Error, Id, Config, e.Message, e);
            }
        }

        //private
        private void BindXMLDocument()
        {
            if (_xmldocument == null)
            {
                xmlTree.ItemsSource = null;
                return;
            }

            var provider = new XmlDataProvider() { Document = _xmldocument };
            var binding = new Binding() { Source = provider, XPath = "child::node()" };
            xmlTree.SetBinding(TreeView.ItemsSourceProperty, binding);
        }

        private void AddFunction(IFunctions funcs)
        {
            _funcs = funcs;
        }
    }
}





























































































//Copyright2013<jnrton>AllRightsReserved 
//Contact j.nrton@finpus